// https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    int findMinArrowShots(vector<vector<int>>& points) {
        int n = points.size();
        if (n == 1) {
            return 1;
        }

        sort(points.begin(), points.end());

        int left = points[0][0];
        int right = points[0][1];
        int count = 0;

        for (auto point : points) {
            int curLeft = point[0];
            int curRight = point[1];

            if (right < curLeft) {
                count++;
                left = curLeft;
                right = curRight;
            } else {
                left = max(left, curLeft);
                right = min(right, curRight);
            }
        }
        return count + 1;
    }
};